classic_battlefield_moddingfandomcom-20200214-history
Add Control points to vehicles
by Hjid27 Some people have asked me if I could give some info on how control points on vehicles work, and with how much I've learned from bfeditor.org I guess I have to contribute a bit. No, I'm not talking about a flag you can add to a vehicle so you have a mobile control point. I'm talking about this: http://www.xfire.com/video/4cfaea/ As you can see in this concept video for Alpha Project, there are destroyable windows and first person hands in the vehicle. If you have tried out the mod you have probably noticed that the 1p hands on the steering wheels and mounted weapons change with the team. If a player on the MEC team enters the civillian car the MEC 1p hands are shown. For a USMC player the USMC hands are shown. This even works on a multiplayer server, but how do we do it? The answer is control points, or flags as people often call them. Flags are one of the few things that BF2 actually use python to manage. Due to code that remained from refractor engine 1 or developers having plans for mobile flags in BF2, the flags can be attached to vehicles and managed by python. By managing, I'm talking about changing the team on the control point so it displays another flag on the flagpole. Instead of changing between a US and a MEC flag, you can set different flag templates on the control point. Example: Hands on Steeringwheel ObjectTemplate.create ControlPoint civ2_hands ObjectTemplate.activeSafe ControlPoint civ2_hands ObjectTemplate.modifiedByUser "Hjid" ObjectTemplate.setNetworkableInfo ControlPointInfo ObjectTemplate.isNotSaveable 1 ObjectTemplate.hasMobilePhysics 0 ObjectTemplate.hasCollisionPhysics 0 ObjectTemplate.physicsType Mesh ObjectTemplate.setControlPointName civ_flag ObjectTemplate.radius 0 ObjectTemplate.showOnMinimap 0 ObjectTemplate.team 0 ObjectTemplate.areaValueTeam1 34 ObjectTemplate.areaValueTeam2 34 ObjectTemplate.timeToGetControl 999999999999 ObjectTemplate.timeToLoseControl 999999999999 ObjectTemplate.hoistMinMax 0.0/0.0 ObjectTemplate.flagTemplateTeam0 nothing ObjectTemplate.flagTemplateTeam1 civ2_mec_hands ObjectTemplate.flagTemplateTeam2 civ2_us_hands This should be the standard template for a flag that you want to attach to a vehicle. Further explanation: ObjectTemplate.create ControlPoint civ2_hands ObjectTemplate.activeSafe ControlPoint civ2_hands ObjectTemplate.modifiedByUser "Hjid" ObjectTemplate.setNetworkableInfo ControlPointInfo ObjectTemplate.isNotSaveable 1 ObjectTemplate.hasMobilePhysics 0 ObjectTemplate.hasCollisionPhysics 0 ObjectTemplate.physicsType Mesh ObjectTemplate.setControlPointName civ_flag Regular control point code for creating a template. ObjectTemplate.radius 0 Since we don't want the control point to be captured by players, we simply remove the flags with a "radius 0" from the list of flags in the conquest gamemode file. ObjectTemplate.showOnMinimap 0 If we didn't use this line, there would be a minimap flag at the center of the minimap("0,0" coordinates). ObjectTemplate.team 0 ObjectTemplate.areaValueTeam1 34 ObjectTemplate.areaValueTeam2 34 ObjectTemplate.timeToGetControl 999999999999 ObjectTemplate.timeToLoseControl 999999999999 ObjectTemplate.hoistMinMax 0.0/0.0 Standard values for the flags, doesn't matter since the flags aren't taken into consideration in the conquest gamemode file(See "radius 0"). ObjectTemplate.flagTemplateTeam0 nothing ObjectTemplate.flagTemplateTeam1 civ2_mec_hands ObjectTemplate.flagTemplateTeam2 civ2_us_hands Probably the most interesting part. By setting the flagTemplate to a template that doesn't exist, the control point will not show anything. This control point will be empty when the team is 0. (Neutral) The civ2_mec_hands and civ2_us_hands are simpleObjects without any networkable info. GeometryTemplate.create BundledMesh civ2_us_hands ObjectTemplate.create SimpleObject civ2_us_hands ObjectTemplate.saveInSeparateFile 1 ObjectTemplate.creator RHYS-COMPUTER:Rhys ObjectTemplate.geometry civ2_us_hands GeometryTemplate.setSubGeometryLodDistance 1 0 0.001 include civ2_us_hands.tweak We use the lodDistance to toggle how far away you should be able to see the hands, so you can't see them through the window. The tweak file does not exist. To add the control point to a vehicle you just add it as you would with any other object. ObjectTemplate.activeSafe RotationalBundle CivilianCar2_Steeringwheel ObjectTemplate.modifiedByUser "Administrator" ObjectTemplate.setNetworkableInfo BasicInfo ObjectTemplate.floaterMod 0 ObjectTemplate.hasMobilePhysics 1 rem ------------------------------------- ObjectTemplate.addTemplate civ2_hands ObjectTemplate.setPosition -0.01020/-0.10596/-0.14147 ObjectTemplate.setRotation 1.5/-25.0/-2.25 That is about all you need to know about the con/tweak coding. Python Code There isn't really anything special in the python code, we use the same code that is used to change flags in the gpm_cq.py file. Highly simplified example: def onEnterVehicle(player, vehicle, freeSoldier = False): for child in vehicle.getChildren(): if child.templateName "civ2_hands": child.cp_setParam("flag",0) child.cp_setParam("flag",player.getTeam()) def onExitVehicle(player, vehicle): for child in vehicle.getChildren(): if child.templateName "civ2_hands": child.cp_setParam("flag",0) Notice that we on the enterVehicle function have to first set the control point to team 0 and then to the correct team. This is to fix bugs due to the flag only updating for the player when changing team. The part that is important for the flags is: controlPoint.cp_setParam("flag",team) Where the controlPoint is the object and team is an integer being either 0, 1 or 2. This example only shows how to add simpleObjects as flagtemplates, but it would be the same procedure for other types of objects. As far as I know SimpleObjects, Bundles, Effects and AnimatedBundles are the objects that seem to work fine as flagTemplates. Setting the flagTemplates to a PCO or a destroyable object causes a crash, so to have destroyable stuff on your vehicle you will have to make a bundle with an armor component and change the flag through python based on damage. There is probably a lot of stuff you can do with these flags, so I hope that this was somewhat helpful